package com.mlt.gwt.test.server;

import org.apache.commons.lang.time.DateUtils;
import org.hibernate.Session;
import com.mlt.gwt.test.server.domain.Appuntamento;
import java.util.*;

public class AppuntamentiManager {

	public static void main(String[] args) {
		AppuntamentiManager mgr = new AppuntamentiManager();

		mgr.createAndStoreEvent("My Meeting1", new Date(), false);
		mgr.createAndStoreEvent("My Meeting2", DateUtils.addHours(new Date(),-10), false);
		mgr.createAndStoreEvent("My Meeting3", DateUtils.addHours(new Date(),-7), true);
	}

	private void createAndStoreEvent(String title, Date theDate, boolean isPrivate) {
		Session session;
		if(isPrivate)
			session = HibernateUtil.getSessionFactory_usb().getCurrentSession();
		else
			session = HibernateUtil.getSessionFactory_hd().getCurrentSession();

		session.beginTransaction();

		Appuntamento appuntamento = new Appuntamento();
		appuntamento.setTitle(title);
		appuntamento.setStartDate(theDate);
		appuntamento.setEndDate(DateUtils.addHours(theDate, 1));
		session.save(appuntamento);

		session.getTransaction().commit();
//		session.close();
	}
}
